<?php Temp::Tinclude("commom/header");?>

<form id="jpform" method="post" action="<{echo Common::RewriteUrl("home","checkout");}>">
<div class="panel panel-default">
  <div class="panel-heading">购物车列表</div>
  <div class="panel-body">
 <?php foreach($cart_cookie as $v){?>
 <div class="media">
  <div class="media-left">
    <a href="<{echo Common::RewriteUrl("Home","detail","&gid=".$v["good_id"]);}>">
        <img class="media-object" src="<?php echo Common::getThumb($v["goods"]["image"],"100x100");?>" alt="<?php echo $v["goods"]["base_name"];?>">
    </a>
  </div>
  <div class="media-body">
      <input type="hidden" name="info[<?php echo $v["good_id"];?>][gid]" value="<?php echo $v["good_id"];?>" />
    <h4 class="media-heading"><?php echo $v["goods"]["base_name"];?></h4>
    <div class="col-md-3 col-xs-12">
    <div class="input-group">
  <span class="input-group-addon">价格：</span>
  <input type="text" name="info[<?php echo $v["good_id"];?>][sale_price]" value="<?php echo $v["sale_price"];?>" data-price="<?php echo $v["sale_price"];?>" class="form-control jgs" placeholder="价格"/>
  <span class="input-group-addon">(元/斤)</span>
    </div>
    </div>
 <div class="col-md-3 col-xs-12">
     <div class="input-group">
  <span class="input-group-addon">重量：</span>
  <input type="text" class="form-control zls" name="info[<?php echo $v["good_id"];?>][sale_weight]" placeholder="重量" value="<?php echo $v["sale_weight"];?>"  />
  <span class="input-group-addon">(斤)</span>
    </div>
 </div>
    
    <div class="col-md-3 col-xs-12">
        <button type="button" class="btn btn-danger deletbtn" data-gid="<?php echo $v["good_id"];?>"><span class="glyphicon glyphicon-trash"></span>删除</button>
    </div>
    
    
  </div>
</div>
  <?php }?>
  <div class="margin_top20">
      <div class="row show-grid">
  <div class="col-md-3 col-xs-12">
     <div class="input-group">
  <span class="input-group-addon">收货人姓名：</span>
  <input type="text" name="user_name" class="form-control" placeholder="姓名"/>
    </div>
  </div>
      
       <div class="col-md-4 col-xs-12">
     <div class="input-group">
  <span class="input-group-addon">收货人联系电话：</span>
  <input type="text" name="user_address" class="form-control" placeholder="电话"/>
    </div>
  </div>
     </div> 
       <div class="row show-grid">
        <div class="col-md-9 col-xs-12">
     <div class="input-group">
  <span class="input-group-addon">收货人地址：</span>
  <input type="text" name="user_phone" class="form-control" placeholder="地址"/>
    </div>
  </div>
       </div>
      
     
  
  </div>
  
  </div>
  
  <div class="panel-footer">
      <p class="bg-primary ppadding"><span class="glyphicon glyphicon-yen"></span>总计:<span id="zongji"><?php echo $zjjg;?>元</span></p>
      <div class="margin_top20"></div>
      <button type="button" class="btn btn-success btn-block" id="mysubmit"><span class="glyphicon glyphicon-shopping-cart"></span>结算</button>
      <div class="margin_top20"></div>
      <button type="button" class="btn btn-default btn-block" id="view"><span class="glyphicon glyphicon-eye-open"></span>继续浏览</button>
      
  </div>
</div>
</form>
<script>
    $(".deletbtn").click(function(){
        var gid=$(this).data("gid");
        if(gid){
            $.post("<{echo Common::RewriteUrl("Home","public_ajax_delete_cart_id");}>",{"gid":gid},function(data){
                if(data.status==1){
                    window.location.reload();
                }else{
                    alert("删除失败!");
                }
            },"json");
        }
    });
    $("#view").click(function(){
        window.location.href="/";
    });
    $(".zls").blur(function(){
       var zl=parseFloat($(this).val());
       if(isNaN(zl)){
             alert("请输入正确的重量");
              $(this).val("0.00");
             $(this).focus();
             return false;
         }else if(zl==0){
             alert("请输入重量");
             $(this).focus();
             return false;
         }
         jisuan();
    });
    $(".jgs").blur(function(){
       var jg=parseFloat($(this).val());
       if(isNaN(jg)){
             alert("请输入正确的价格");
             $(this).val($(this).data("price"));
             $(this).focus();
             return false;
         }else if(jg==0){
             alert("请输入价格");
             $(this).focus();
             return false;
         }
         jisuan();
    });
    
    function jisuan(){
        var zj=0.0;
        $(".jgs").each(function(){
            var jg=parseFloat($(this).val());
            var zl=parseFloat($(this).parent().parent().parent().find(".zls").val());
            zj+=jg*zl;
        });
       $("#zongji").html(zj.toFixed(2)+"元");
    }
    $(document).ready(function(){
        $("#mysubmit").click(function(){
        var user_name=$("input[name='user_name']").val();
        if(user_name==""){
            alert("请输入收货人姓名！");
            $("input[name='user_name']").focus();
            return false;
        }
        $("#jpform").submit();
    });
    });
    
</script>

<?php Temp::Tinclude("commom/footer");?>